/******************************************************************/
/*                                                                */
/*  Winpooch : Windows Watchdog                                   */
/*  Copyright (C) 2004-2005  Benoit Blanchon                      */
/*                                                                */
/*  This program is free software; you can redistribute it        */
/*  and/or modify it under the terms of the GNU General Public    */
/*  License as published by the Free Software Foundation; either  */
/*  version 2 of the License, or (at your option) any later       */
/*  version.                                                      */
/*                                                                */
/*  This program is distributed in the hope that it will be       */
/*  useful, but WITHOUT ANY WARRANTY; without even the implied    */
/*  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR       */
/*  PURPOSE.  See the GNU General Public License for more         */
/*  details.                                                      */
/*                                                                */
/*  You should have received a copy of the GNU General Public     */
/*  License along with this program; if not, write to the Free    */
/*  Software Foundation, Inc.,                                    */
/*  675 Mass Ave, Cambridge, MA 02139, USA.                       */
/*                                                                */
/******************************************************************/


/******************************************************************/
/* Includes                                                       */
/******************************************************************/

// module's interface
#include "Rule.h"

// standard headers
#include <stdio.h>
#include <tchar.h>

// project's headers
#include "Assert.h"
#include "Language.h"
#include "Strlcpy.h"


/******************************************************************/
/* Internal macros                                                */
/******************************************************************/

#define arraysize(A) (sizeof(A)/sizeof((A)[0]))

UINT Rule_GetReactionString (RULE * pRule, LPTSTR szOutput, UINT nOutputMax) 
{
  LPCTSTR szResult = NULL ;

  if( pRule->nOptions & RULE_ASK )
    {
      switch( pRule->nReaction )
	{
	case RULE_ACCEPT:
	  szResult = STR_DEF (_ASK_DEFAULT_ACCEPT, TEXT("Ask (default Accept)")) ;
	  break ;
	case RULE_FEIGN:
	  szResult = STR_DEF (_ASK_DEFAULT_FEIGN, TEXT("Ask (default Feign)")) ;
	  break ;
	case RULE_REJECT:
	  szResult = STR_DEF (_ASK_DEFAULT_REJECT, TEXT("Ask (default Reject)")) ;
	  break ;
	case RULE_KILLPROCESS:
	  szResult = STR_DEF (_ASK_DEFAULT_KILL_PROCESS, TEXT("Ask (default Kill process)")) ;
	  break ;
	default:
	  ASSERT(0) ;
	}
    }
  else
    {
      switch( pRule->nReaction )
	{
	case RULE_ACCEPT:
	  szResult = STR_DEF (_ACCEPT, TEXT("Accept")) ;
	  break ;
	case RULE_FEIGN:
	  szResult = STR_DEF (_FEIGN, TEXT("Feign")) ;
	  break ;
	case RULE_REJECT:
	  szResult = STR_DEF (_REJECT, TEXT("Reject")) ;
	  break ;
	case RULE_KILLPROCESS:
	  szResult = STR_DEF (_KILL_PROCESS, TEXT("Kill process")) ;
	  break ;
	default:
	  ASSERT(0) ;
	}      
    }

  ASSERT (szResult!=NULL) ;
  
  return _tcslcpy (szOutput, szResult, nOutputMax) ;
}


UINT Rule_GetVerbosityString (RULE * pRule, LPTSTR szOutput, UINT nOutputMax) 
{
  LPCTSTR szResult = NULL ;

  switch( pRule->nVerbosity )
    {
    case RULE_SILENT:
      szResult = STR_DEF (_SILENT, TEXT("Silent")) ;
      break ;      
    case RULE_LOG:
      szResult = STR_DEF (_LOG, TEXT("Log")) ;
      break ;
    case RULE_ALERT:
      szResult = STR_DEF (_ALERT, TEXT("Alert")) ;
      break ;
    default:
      ASSERT (0) ;
    }

  ASSERT (szResult!=NULL) ;

  return _tcslcpy (szOutput, szResult, nOutputMax) ;
}


UINT Rule_GetOptionsString (RULE * pRule, LPTSTR szOutput, UINT nOutputMax) 
{
  szOutput[0] = 0 ;

  if( pRule->nOptions & RULE_SCAN )
    _tcslcpy (szOutput, 
	      STR_DEF (_VIRUS_SCAN, TEXT("Scan")), 
	      nOutputMax) ;
   
  return _tcslen (szOutput) ;
}
